﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Specialized;
using System.Reflection;
using System.IO;

namespace com.huawei.esdk.tp.professional.Utils
{
    internal static class UtilsSettings
    {
        internal static Configuration appSettings = null;

        static UtilsSettings()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            //通过URL获取时目录中含有#时出现问题
            //Uri uri = new Uri(Path.GetDirectoryName(assembly.CodeBase));
            ExeConfigurationFileMap map = new ExeConfigurationFileMap();

            map.ExeConfigFilename = Assembly.GetExecutingAssembly().CodeBase.Replace(@"file:///", string.Empty) + ".config";
            //map.ExeConfigFilename = Path.Combine("C:\\Users\\l00206656\\Desktop\\uc_sdk_20_foundation_cs_2008\\com.huawei.ebg.tp.ucsdkserver.foundation\\bin\\Debug", assembly.GetName().Name + ".dll.config");
            appSettings = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

            //MessageBox.Show(map.ExeConfigFilename);
        }

        private static string _URL;
        internal static string URL
        {
            get
            {
                if (_URL == null)
                {
                    if (appSettings.AppSettings.Settings["url"] == null)
                    {
                        _URL = "http://localhost:8086/esdk/services/";
                    }
                    else
                    {
                        _URL = appSettings.AppSettings.Settings["url"].Value;
                    }
                }
                return _URL;
            }
        }

        private static string _EncryptMode;
        internal static string EncryptMode
        {
            get
            {
                if (_EncryptMode == null)
                {
                    if (appSettings.AppSettings.Settings["sensitive.information.transmission.mode"] == null)
                    {
                        _EncryptMode = "AES128_consulted";
                    }
                    else
                    {
                        _EncryptMode = appSettings.AppSettings.Settings["sensitive.information.transmission.mode"].Value;
                    }
                }
                return _EncryptMode;
            }
        }

        private static string _tpCommon;
        internal static string tpCommon
        {
            get
            {
                if (_tpCommon == null)
                {
                    if (appSettings.AppSettings.Settings["tpCommon"] == null)
                    {
                        _tpCommon = "tpCommon";
                    }
                    else
                    {
                        _tpCommon = appSettings.AppSettings.Settings["tpCommon"].Value;
                    }
                }
                return _tpCommon;
            }
        }

        private static string _tpProfessionalConfCtrl;
        internal static string tpProfessionalConfCtrl
        {
            get
            {
                if (_tpProfessionalConfCtrl == null)
                {
                    if (appSettings.AppSettings.Settings["tpProfessionalConfCtrl"] == null)
                    {
                        _tpProfessionalConfCtrl = "tpProfessionalConfCtrl";
                    }
                    else
                    {
                        _tpProfessionalConfCtrl = appSettings.AppSettings.Settings["tpProfessionalConfCtrl"].Value;
                    }
                }
                return _tpProfessionalConfCtrl;
            }
        }

        private static string _tpProfessionalConfMgr;
        internal static string tpProfessionalConfMgr
        {
            get
            {
                if (_tpProfessionalConfMgr == null)
                {
                    if (appSettings.AppSettings.Settings["tpProfessionalConfMgr"] == null)
                    {
                        _tpProfessionalConfMgr = "tpProfessionalConfMgr";
                    }
                    else
                    {
                        _tpProfessionalConfMgr = appSettings.AppSettings.Settings["tpProfessionalConfMgr"].Value;
                    }
                }
                return _tpProfessionalConfMgr;
            }
        }

        private static string _tpProfessionalSiteMgr;
        internal static string tpProfessionalSiteMgr
        {
            get
            {
                if (_tpProfessionalSiteMgr == null)
                {
                    if (appSettings.AppSettings.Settings["tpProfessionalSiteMgr"] == null)
                    {
                        _tpProfessionalSiteMgr = "tpProfessionalSiteMgr";
                    }
                    else
                    {
                        _tpProfessionalSiteMgr = appSettings.AppSettings.Settings["tpProfessionalSiteMgr"].Value;
                    }
                }
                return _tpProfessionalSiteMgr;
            }
        }

        private static string _tpProfessionalMCUMgr;
        internal static string tpProfessionalMCUMgr
        {
            get
            {
                if (_tpProfessionalMCUMgr == null)
                {
                    if (appSettings.AppSettings.Settings["tpProfessionalMCUMgr"] == null)
                    {
                        _tpProfessionalMCUMgr = "tpProfessionalMCUMgr";
                    }
                    else
                    {
                        _tpProfessionalMCUMgr = appSettings.AppSettings.Settings["tpProfessionalMCUMgr"].Value;
                    }
                }
                return _tpProfessionalMCUMgr;
            }
        }

        private static string _tpProfessionalOrgaMgr;
        internal static string tpProfessionalOrgaMgr
        {
            get
            {
                if (_tpProfessionalOrgaMgr == null)
                {
                    if (appSettings.AppSettings.Settings["tpProfessionalOrgaMgr"] == null)
                    {
                        _tpProfessionalOrgaMgr = "tpProfessionalOrgaMgr";
                    }
                    else
                    {
                        _tpProfessionalOrgaMgr = appSettings.AppSettings.Settings["tpProfessionalOrgaMgr"].Value;
                    }
                }
                return _tpProfessionalOrgaMgr;
            }
        }

        private static string _tpProfessionalTerminalConfCtr;
        internal static string tpProfessionalTerminalConfCtr
        {
            get
            {
                if (_tpProfessionalTerminalConfCtr == null)
                {
                    if (appSettings.AppSettings.Settings["tpProfessionalTerminalConfCtr"] == null)
                    {
                        _tpProfessionalTerminalConfCtr = "tpProfessionalTerminalConfCtr";
                    }
                    else
                    {
                        _tpProfessionalTerminalConfCtr = appSettings.AppSettings.Settings["tpProfessionalTerminalConfCtr"].Value;
                    }
                }
                return _tpProfessionalTerminalConfCtr;
            }
        }

        private static string _platformKeyMgr;
        internal static string platformKeyMgr
        {
            get
            {
                if (_platformKeyMgr == null)
                {
                    if (appSettings.AppSettings.Settings["platformKeyMgr"] == null)
                    {
                        _platformKeyMgr = "platformKeyMgr";
                    }
                    else
                    {
                        _platformKeyMgr = appSettings.AppSettings.Settings["platformKeyMgr"].Value;
                    }
                }
                return _platformKeyMgr;
            }
        }
    }
}
